home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / undostate.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-05-09  |  11.0 KB  |  299 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. /***************************************************************************
  8.  *   Copyright (C) 2005 by Riku Leino                                      *
  9.  *   riku@scribus.info                                                     *
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  *   This program is distributed in the hope that it will be useful,       *
  17.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  18.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  19.  *   GNU General Public License for more details.                          *
  20.  *                                                                         *
  21.  *   You should have received a copy of the GNU General Public License     *
  22.  *   along with this program; if not, write to the                         *
  23.  *   Free Software Foundation, Inc.,                                       *
  24.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  25.  ***************************************************************************/
  26.  
  27. #ifndef UNDOSTATE_H
  28. #define UNDOSTATE_H
  29.  
  30. #include <QMap>
  31. #include <QPixmap>
  32. #include <QVariant>
  33.  
  34. #include "scribusapi.h"
  35. #include "undoobject.h"
  36.  
  37. class QString;
  38. class PageItem;
  39.  
  40. /**
  41.  * @brief UndoState describes an undoable state (action).
  42.  *
  43.  * Undoable objects implement undo/redo by sending and receiving UndoState
  44.  * subclasses. This means that they will need to produce some sort of information
  45.  * for the UndoState subclass (if no suitable subclass exists it must be also
  46.  * created) and later they will need to be able to restore the state described
  47.  * by the subclass to apply undo/redo.
  48.  *
  49.  * UndoManager will handle the deletion of UndoState objects.
  50.  *
  51.  * @sa SimpleState
  52.  * @author Riku Leino riku@scribus.info
  53.  * @date December 2004
  54.  */
  55. class SCRIBUS_API UndoState
  56. {
  57. public:
  58.     /**
  59.      * @brief Creates a new UndoState instance.
  60.      * @param name Name of the state (action). Will be used when describing the
  61.      * state in UndoGui subclasses.
  62.      * @param description Description of the state (action)
  63.      * @param pixmap Pointer to an icon describing the action visually.
  64.      */
  65.     UndoState(const QString& name, const QString& description = 0, QPixmap* pixmap = 0);
  66.  
  67.     virtual ~UndoState();
  68.  
  69.     /**
  70.      * @brief Returns name of the state (action).
  71.      * @return name of the state
  72.      */
  73.     virtual QString getName();
  74.  
  75.     /**
  76.      * @brief Set the name for this UndoState.
  77.      * @param newName name for this UndoState
  78.      */
  79.     virtual void setName(const QString &newName);
  80.  
  81.     /**
  82.      * @brief Returns description of the state.
  83.      * @return description of the state
  84.      */
  85.     virtual QString getDescription();
  86.  
  87.     /**
  88.      * @brief Set the description for this UndoState
  89.      * @param newDescription description for this UndoState
  90.      */
  91.     virtual void setDescription(const QString &newDescription);
  92.  
  93.     /**
  94.      * @brief Returns a pointer to the icon attached to the state.
  95.      * @return A pointer to the icon attached to the state
  96.      */
  97.     virtual QPixmap* getPixmap();
  98.  
  99.     /**
  100.      * @brief Set the icon for this UndoState.
  101.      * @param newPixmap icon for this UndoState
  102.      */
  103.     virtual void setPixmap(QPixmap *newPixmap);
  104.  
  105.     /** @brief undo the state described by this UndoState,
  106.      *  @brief requires related UndoObject */
  107.     virtual void undo();
  108.     /** @brief redo the state described by this UndoState,
  109.      *  @brief requires the related UndoObject */
  110.     virtual void redo();
  111.  
  112.     /** @brief Set the UndoObject this state belongs to */
  113.     virtual void setUndoObject(UndoObject *object);
  114.     /** @brief return the UndoObject this state belongs to */
  115.     virtual UndoObject* undoObject();
  116.     int transactionCode;
  117.  
  118. private:
  119.     /** @brief Name of the state (operation) (f.e. Move object) */
  120.     QString actionName_;
  121.     /** @brief Detailed description of the state (operation). */
  122.     QString actionDescription_;
  123.     /** @brief Icon related to the state (operation) */
  124.     QPixmap *actionPixmap_;
  125.     /** @brief UndoObject this state belongs to */
  126.     UndoObjectPtr undoObject_;
  127. };
  128.  
  129. /*** SimpleState **************************************************************************/
  130.  
  131. /**
  132.  * @brief SimpleState provides a simple implementation of the UndoState.
  133.  *
  134.  * SimpleState uses a <code>QMap</code> to store key-value pairs that can be queried and
  135.  * set using it's get() and set() methods.
  136.  *
  137.  * @author Riku Leino tsoots@gmail.com
  138.  * @date December 2004
  139.  */
  140. class SCRIBUS_API SimpleState : public UndoState
  141. {
  142. public:
  143.     /**
  144.      * @brief Creates a new SimpleState instance.
  145.      * @param name Name of the state (action). Will be used when describing the
  146.      * state in UndoGui subclasses.
  147.      * @param description Description of the state (action)
  148.      * @param pixmap Pointer to an icon describing the state (action) visually.
  149.      */
  150.     SimpleState(const QString& name, const QString& description = 0, QPixmap* pixmap = 0);
  151.  
  152.     virtual ~SimpleState();
  153.  
  154.     /**
  155.      * @brief Returns true if parameter key exists in the map.
  156.      * @param key Key that is searched from the map
  157.      * @return true if parameter key exists in the map if not false
  158.      */
  159.     bool contains(const QString& key);
  160.  
  161.     /**
  162.      * @brief Returns the QString value attached to the key.
  163.      *
  164.      * If key is not found from the map it will be added there with the
  165.      * value given as a parameter def. In such case <code>def</code> will also
  166.      * be returned.
  167.      * @param key Key that is searched from the map
  168.      * @param def Default value to be used if key is not found from the map
  169.      * @return Value attached to the key in the map. If the key is not found
  170.      * from the map it will be added with the value described in the param
  171.      * <code>def</code> which is then returned.
  172.      */
  173.     QString get(const QString& key, const QString& def = "");
  174.  
  175.     /**
  176.      * @brief Returns the int value attached to the key.
  177.      *
  178.      * Values are stored as <code>QString</code>s in the map and when queried
  179.      * with this method value attached to the key is converted to an int. If
  180.      * the conversion fails value of the parameter <code>def</code> will be returned.
  181.      * If key is not found from the map it will be added there with the
  182.      * value given as a parameter <code>def</code>. In such case <code>def</code>
  183.      * will also be returned.
  184.      * @param key Key that is searched from the map
  185.      * @param def Default value to be used if key is not found from the map
  186.      * @return <code>int</code> value attached to the key in the map. If the key is not found
  187.      * from the map it will be added with the value described in the param
  188.      * <code>def</code> which is then returned.
  189.      */
  190.     int getInt(const QString& key, int def = 0);
  191.  
  192.     /**
  193.      * @brief Returns the uint value attached to the key.
  194.      *
  195.      * Values are stored as <code>QString</code>s in the map and when queried
  196.      * with this method value attached to the key is converted to an int. If
  197.      * the conversion fails value of the parameter <code>def</code> will be returned.
  198.      * If key is not found from the map it will be added there with the
  199.      * value given as a parameter <code>def</code>. In such case <code>def</code>
  200.      * will also be returned.
  201.      * @param key Key that is searched from the map
  202.      * @param def Default value to be used if key is not found from the map
  203.      * @return <code>uint</code> value attached to the key in the map. If the key is not found
  204.      * from the map it will be added with the value described in the param
  205.      * <code>def</code> which is then returned.
  206.      */
  207.     uint getUInt(const QString& key, uint def = 0);
  208.  
  209.     /**
  210.      * @brief Returns the double value attached to the key.
  211.      *
  212.      * Values are stored as <code>QString</code>s in the map and when queried
  213.      * with this method value attached to the key is converted to a double. If
  214.      * the conversion fails value of the parameter <code>def</code> will be returned.
  215.      * If key is not found from the map it will be added there with the
  216.      * value given as a parameter def. In such case <code>def</code> will also be returned.
  217.      * @param key Key that is searched from the map
  218.      * @param def Default value to be used if key is not found from the map
  219.      * @return <code>Double</code> value attached to the key in the map. If the key is not found
  220.      * from the map it will be added with the value described in the parameter
  221.      * <code>def</code> which is then returned.
  222.      */
  223.     double getDouble(const QString& key, double def = 0.0);
  224.  
  225.     /**
  226.      * @brief Returns the boolean value attached to the key.
  227.      *
  228.      * Values are stored as <code>QString</code>s in the map and when queried
  229.      * with this method value attached to the key is converted to a bool. If
  230.      * the conversion fails value of the parameter <code>def</code> will be returned.
  231.      * If key is not found from the map it will be added there with the
  232.      * value given as a parameter def. In such case <code>def</code> will also be returned.
  233.      * @param key Key that is searched from the map
  234.      * @param def Default value to be used if key is not found from the map
  235.      * @return <code>Bool</code> value attached to the key in the map. If the key is not found
  236.      * from the map it will be added with the value described in the parameter
  237.      * <code>def</code> which is then returned.
  238.      */
  239.     bool getBool(const QString& key, bool def = false);
  240.  
  241.     /**
  242.      * @brief Set a value for the key.
  243.      * @param key Key that can be later used to query the value.
  244.      * @param value Value attached to the key.
  245.      */
  246.     void set(const QString& key, const QString& value);
  247.  
  248.     /**
  249.      * @brief Set a value for the key.
  250.      * @param key Key that can be later used to query the value.
  251.      * @param value Value attached to the key.
  252.      */
  253.     void set(const QString& key, int value);
  254.  
  255.     /**
  256.      * @brief Set a value for the key.
  257.      * @param key Key that can be later used to query the value.
  258.      * @param value Value attached to the key.
  259.      */
  260.     void set(const QString& key, uint value);
  261.  
  262.     /**
  263.      * @brief Set a value for the key.
  264.      * @param key Key that can be later used to query the value.
  265.      * @param value Value attached to the key.
  266.      */
  267.     void set(const QString& key, double value);
  268.  
  269.     /**
  270.      * @brief Set a value for the key.
  271.      * @param key Key that can be later used to query the value.
  272.      * @param value Value attached to the key.
  273.      */
  274.     void set(const QString& key, bool value);
  275.  
  276. private:
  277.     /** @brief QMap to store key-value pairs */
  278.     QMap<QString, QVariant> values_;
  279.  
  280.     QVariant variant(const QString& key, const QVariant& def);
  281. };
  282.  
  283. /*** ItemState ***************************************************************************/
  284.  
  285. template<class C>
  286. class ItemState : public SimpleState
  287. {
  288. public:
  289.     ItemState(const QString& name, const QString& description = 0, QPixmap* pixmap = 0)
  290.     : SimpleState(name, description, pixmap) {}
  291.     ~ItemState() {}
  292.     void setItem(const C &c) { item_ = c; }
  293.     C getItem() const { return item_; }
  294. private:
  295.     C item_;
  296. };
  297.  
  298. #endif
  299.